<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Jury extends CI_Controller {

	public function index()
	{
		header('Location: '.base_url()); // redirection
	}

	//formulaire inscription du jury
	public function inscription(){
		$data['page'] = 'home';
		$data['cats'] = $this->model->readCat();
		$data['schls'] = $this->model->readSchool();
		$this->template->load('template', 'ins_jury_message',$data);
	}
	
	// Page Jury -> page de notation
	public function notation() {
		$group = "1";
		$data['groupe'] = $this->model->readOneGroup($group);
		$data['categorys'] = $this->model->readAllCategory();
		$data['items'] = $this->model->readAllItem();

		$this->calculateProgress($group);
		$this->template->load('template', 'notation', $data);
	}

	public function calculateProgress($group){
		$tasks = $this->model->readTaskPerGroup($group);
		$n=0;
		$FK_ITM_laste=0;
		$data = null;
		foreach ($tasks as $value) {

			if ($FK_ITM_laste == $value->FK_ITM) {
				$n = $n +1;
				$dateStart = new DateTime($value->TSK_start_hour_plan);
				$dateEnd = new DateTime($value->TSK_end_hour_plan);
				$dateInterval = $dateStart->diff($dateEnd);

				$int = (int) preg_replace('/[^0-9]/', '', $dateInterval->h);
				$int = $int + 1;
				$date = strtotime("1970-01-01 ".$int.":".$dateInterval->i.":00");
				$data[$value->FK_ITM][$n] = $date;

			}else{
				$FK_ITM_laste = $value->FK_ITM;
				$n = 0;
				$dateStart = new DateTime($value->TSK_start_hour_plan);
				$dateEnd = new DateTime($value->TSK_end_hour_plan);
				$dateInterval = $dateStart->diff($dateEnd);

				$int = (int) preg_replace('/[^0-9]/', '', $dateInterval->h);
				$int = $int + 1;
				$date = strtotime("1970-01-01 ".$int.":".$dateInterval->i.":00");
				$data[$value->FK_ITM][$n] = $date;

			}

		}
		var_dump($data);
	}



}